﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using PersistentObject.Common;
using PersistentObject.Common.Criteria;
using PersistentObject.SqlServer2012;
using PersistentObject.StudentTest.Entities;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PersistentObject.StudentTest
{
    public abstract class TransactionTest
    {
        public abstract BaseDialect Dialect { get; }
        public POConnection Connection { get; set; }
        static string IMAGE_PATH = @"D:\logo.png";
        public abstract string ConfigName { get; }

        public TransactionTest()
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings[ConfigName].ConnectionString;
            Connection = new POConnection(ConnectionString, Dialect);
        }

        [TestMethod]
        public void Transaction()
        {
            Connection.BeginTransaction();
            Student r1 = new Student() { FirstName = "Test", LastName = "Test" };
            Connection.Save<Student>(r1);
            Assert.AreEqual(r1.Id > 0, true);

            Student r2 = new Student() { FirstName = "Test", LastName = "Test" };
            Connection.Save<Student>(r2);
            Assert.AreEqual(r2.Id > 0, true);

            BaseCriteria c3 = new BinaryCriteria("FirstName", "Test");
            Connection.Delete<Student>(c3);
            Connection.CommitTransaction();

            var r3 = Connection.Load<Student>(c3);
            Assert.AreEqual(r3.Count() == 0, true);
        }
    }
}
